#!/bin/bash

# Start All Providers Script
# Author: BCXJ
# Version: 1.0

echo "================================================="
echo "Starting All Dubbo Providers..."
echo "================================================="

# Check if Zookeeper is running
echo "Checking Zookeeper connection..."
nc -z 192.168.1.150 2181
if [ $? -ne 0 ]; then
    echo "ERROR: Zookeeper is not running on 192.168.1.150:2181"
    echo "Please start Zookeeper first!"
    exit 1
fi

echo "Zookeeper is running..."
echo ""

PROJECT_DIR="$(dirname "$0")"

# Start Annotation Provider in background
echo "Starting Annotation Provider..."
cd "$PROJECT_DIR/demo-dubbo-service"
nohup mvn exec:java -Dexec.mainClass="org.example.provider.AnnotationProviderApplication" > annotation-provider.log 2>&1 &
ANNOTATION_PID=$!
echo "Annotation Provider started with PID: $ANNOTATION_PID"
echo $ANNOTATION_PID > annotation-provider.pid
echo ""

sleep 3

# Start XML Provider in background
echo "Starting XML Provider..."
cd "$PROJECT_DIR/demo-dubbo-service"
nohup mvn exec:java -Dexec.mainClass="org.example.provider.XmlProviderApplication" > xml-provider.log 2>&1 &
XML_PID=$!
echo "XML Provider started with PID: $XML_PID"
echo $XML_PID > xml-provider.pid
echo ""

echo "================================================="
echo "All providers started successfully!"
echo "Annotation Provider PID: $ANNOTATION_PID"
echo "XML Provider PID: $XML_PID"
echo "================================================="
echo ""
echo "To stop providers, run: ./stop-all-providers.sh"

